﻿using SCG.General;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace SCG.WinForms
{
    public static class PenBrushFactory
    {
        //get a pen of the specified color
        public static Pen GetPen(SCGColor color)
        {
            string code = color.ToString();
            if (_pens.ContainsKey(code))
                return _pens[code];
            else
            {
                Pen pen = new Pen(color.ToColor());
                _pens[code] = pen;
                return pen;
            }
        }

        //get a brush of the specified color
        public static Brush GetBrush(SCGColor color)
        {
            string code = color.ToString();
            if (_brushes.ContainsKey(code))
                return _brushes[code];
            else
            {
                SolidBrush brush = new SolidBrush(color.ToColor());
                _brushes[code] = brush;
                return brush;
            }
        }

        //private members
        private static Dictionary<string, Pen> _pens = new Dictionary<string, Pen>();
        private static Dictionary<string, Brush> _brushes = new Dictionary<string, Brush>();
    }
}
